﻿using MediatR;
using System.Reflection.Metadata;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.PartitionWarehousings
{
    public class SplitRUupdateHandler : IRequestHandler<SplitRUupdateCommond, Resqults>
    {

        private readonly IBateRepository<SplitRU> _SplitRU;

        public SplitRUupdateHandler(IBateRepository<SplitRU> splitRU
            )
        {
            _SplitRU = splitRU;
        }

        public async Task<Resqults> Handle(SplitRUupdateCommond request, CancellationToken cancellationToken)
        {

            var query = new Resqults() {Code=0 };

            var listquery = _SplitRU.GetAll().FirstOrDefault(x => x.SplitWarehousingId == request.SplitWarehousingId);

         if(listquery!=null)
            {
             
               listquery.SplitWarehousingId = request.SplitWarehousingId;
               listquery.WeightNum = request.WeightNum;
               listquery.GrossWeight = request.GrossWeight;
               listquery.DocumentsDate = DateTime.Now;
               listquery.Tare = request.Tare;
               listquery.NetWeight = request.NetWeight;
                listquery.DocumentNo=request.DocumentNo;

              var uh=await   _SplitRU.Update(listquery);
                query.Code = uh;
            }

            return query;
            




        }
    }
}
